-- wear_apply_skill
-- create by shuzy
-- 首次穿戴施放技能xx

return {
    apply = function(prop, baseValue)
        -- 数量
        return prop[3];
    end,

    record = function(target, prop, path)
        return false;
    end,

    -- 穿戴装备触发
    trigger = function(who, prop, classId)
        local key = prop[2];
        local propId = tonumber(prop[1]);
        local skillId = tonumber(prop[3]);

        -- 预先处理一下
        if not EquipM.doWearTrigger(who, classId, propId, key) then
            return 0;
        end

        local target;
        local skills = SkillM.getSkillTable();
        if not skills[skillId] then
            return;
        end

        -- 目标
        local grid;
        if not SkillM.needTarget(skillId) then
            target = who;
        else
            for p = 1, DUNGEON_WIDTH * DUNGEON_HEIGHT do
                grid = DungeonM.getGridByPos(p);

                -- 是未死亡的怪物
                if grid:isOpened() and
                   grid:isMonster() and
                   not grid.monster:isDead() then
                    target = grid.monster;
                    break;
                end
            end

            -- 已经没有目标了，不处理
            if not target then
                return;
            end
        end

        local round = CombatM.getRound();

        SkillM.apply(who, target, skillId, round);

        return prop[3];
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        local skillId = tonumber(prop[3]);
        local name = SkillM.query(skillId, "name");

        desc = string.gsub(desc, "{1}", name);

        return desc;
    end,
};
